home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TUTOROOT.PAK / STEP04.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  103 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1994 by Borland International
  3. //   Tutorial application -- step04.cpp
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/framewin.h>
  8. #include <owl/dc.h>
  9.  
  10. class TDrawWindow : public TWindow {
  11.   public:
  12.     TDrawWindow(TWindow* parent = 0);
  13.    ~TDrawWindow()
  14.     {
  15.       delete DragDC;
  16.     }
  17.  
  18.   protected:
  19.     TDC* DragDC;
  20.  
  21.     // Override member function of TWindow
  22.     bool CanClose();
  23.  
  24.     // Message response functions
  25.     void EvLButtonDown(uint, TPoint&);
  26.     void EvRButtonDown(uint, TPoint&);
  27.     void EvMouseMove(uint, TPoint&);
  28.     void EvLButtonUp(uint, TPoint&);
  29.  
  30.   DECLARE_RESPONSE_TABLE(TDrawWindow);
  31. };
  32.  
  33. DEFINE_RESPONSE_TABLE1(TDrawWindow, TWindow)
  34.   EV_WM_LBUTTONDOWN,
  35.   EV_WM_RBUTTONDOWN,
  36.   EV_WM_MOUSEMOVE,
  37.   EV_WM_LBUTTONUP,
  38. END_RESPONSE_TABLE;
  39.  
  40. TDrawWindow::TDrawWindow(TWindow* parent)
  41. {
  42.   Init(parent, 0, 0);
  43.   DragDC = 0;
  44. }
  45.  
  46. bool
  47. TDrawWindow::CanClose()
  48. {
  49.   return MessageBox("Do you want to save?", "Drawing has changed",
  50.                     MB_YESNO | MB_ICONQUESTION) == IDNO;
  51. }
  52.  
  53. void
  54. TDrawWindow::EvLButtonDown(uint, TPoint& point)
  55. {
  56.   Invalidate();
  57.  
  58.   if (!DragDC) {
  59.     SetCapture();
  60.     DragDC = new TClientDC(*this);
  61.     DragDC->MoveTo(point);
  62.   }
  63. }
  64.  
  65. void
  66. TDrawWindow::EvRButtonDown(uint, TPoint&)
  67. {
  68.   Invalidate();
  69. }
  70.  
  71. void
  72. TDrawWindow::EvMouseMove(uint, TPoint& point)
  73. {
  74.   if (DragDC)
  75.     DragDC->LineTo(point);
  76. }
  77.  
  78. void
  79. TDrawWindow::EvLButtonUp(uint, TPoint&)
  80. {
  81.   if (DragDC) {
  82.     ReleaseCapture();
  83.     delete DragDC;
  84.     DragDC = 0;
  85.   }
  86. }
  87.  
  88. class TDrawApp : public TApplication {
  89.   public:
  90.     TDrawApp() : TApplication() {}
  91.  
  92.     void InitMainWindow()
  93.     {
  94.       SetMainWindow(new TFrameWindow(0, "Drawing Pad", new TDrawWindow));
  95.     }
  96. };
  97.  
  98. int
  99. OwlMain(int /*argc*/, char* /*argv*/ [])
  100. {
  101.   return TDrawApp().Run();
  102. }
  103.